<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class AppListForm extends CFormModel implements IMiniyunGridConfig
{
	public $searchKey;	public $action;	public $baseAction;
	public $baseActionArray = array(""=>"批量操作","disabled"=>"冻结","enabled"=>"解冻","delete"=>"删除");


	public function rules()
	{
		return array(
		array('searchKey,action,baseAction,roleAction', 'length','max'=>128),
		); 
	}

	public function init(){
		parent::init();
		$this->baseAction="";
	}
	
	public function getFormFilters(){
		return array(
             'enabled'=>array(
              "condition"=>"select osr_id as id from ".Yii::app()->params['tablePrefix']."server_registry where osr_enabled=1 and osr_usa_id_ref != -1"
              ),
              'disabled'=>array(
              "condition"=>"select osr_id as id from ".Yii::app()->params['tablePrefix']."server_registry where osr_enabled=0 and osr_usa_id_ref != -1"
              ),
              );
	}
	
	private function _getMultiNextActions(){
		return array(
            'baseAction'=>array(                "disabled"=>Yii::app()->createUrl("adminApp/disabled"),
                "enabled"=>Yii::app()->createUrl("adminApp/enabled"),
                "delete"=>Yii::app()->createUrl("adminApp/delete")
		),
		);
	}
	public function getSearchKey(){
		if($this->action=="search"){			$key = $this->searchKey;
			return "select osr_id from ".Yii::app()->params['tablePrefix']."server_registry where osr_requester_name like '%$key%'";
		}
	}
	
	public function getDataProvider()
	{
		return new AppListDataProvider($this);
	}
	
	public function mutiAction(){
		$list = $this->_getMultiNextActions();
        if($this->action=="baseAction"){
			if(isset($this->baseAction) && strlen($this->baseAction)>0){
				$url = $list["baseAction"][$this->baseAction];
			}
		}
		if(isset($url)){
			$ids = Yii::app()->request->getParam("selectItems");
			if($ids!='' && $url!=''){
								$url = $url."&id=".implode(",", array_values($ids));;
				Yii::app()->getController()->redirect($url);
				return true;
			}
		}
		return false;
	}
}
